package com.ujson.chat.server.handler;

import com.ujson.base.common.utils.LogUtil;
import com.ujson.chat.common.handler.AbstractHandler;
import com.ujson.chat.common.proto.MessageProto;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * <h3>ujson-parent</h3>
 * <p>全局异常处理器</p>
 *
 * @author JerryLiu  a1031757312@gmail.com
 * @version 1.0
 * @date 2021-11-23 22:57
 */
@Slf4j
@Service
@ChannelHandler.Sharable
public class ExceptionHandler extends AbstractHandler {
    public MessageProto.MessageType getMessageType() {
        return null;
    }

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {

        if (!super.messageTypeCheck(ctx, msg)) {
            return ;
        }
        // startt business handle
        LogUtil.info(log, "exception read");




    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        LogUtil.error(log, "handler global exception.", cause);
        ctx.close();
    }
}
